[TOC]

Logical

True and false are represented by a non-zero number and a zero, respectively. For instance, the built-in functions true() and false() return 1 and 0, respectively:

Input
[true, false]
Output
ans = 
1  0

For logical operations (such as &&), an operand with non-zero value means true, and an operand with zero value means false:

Input
1 && 0
1 && -1
Output
ans = 
0

ans = 
1

All of the following numbers mean true:

1, -1, 0.03, -0.03, 1e-3, Inf, -Inf

Hence, in the code below, for value equal to any of the above values, b = 10 will be executed. If value is 0, then b = 20 is executed.

if value
    b = 10
else
    b = 20
end

Logical operation with characters are possible since a character is represented by an integer or a sequence of integers, which are convertible to logical values:

Input
% The emoji is encoded by 2 integers.
'🙅'&&0
% 'a' is encoded by 1 integer (ASCII code)
'a'&1
Output
ans = 
0  0

ans = 
1

⚠️ It should be noted that NaN and complex numbers are neither true nor false. Hence, attempting to convert NaN or a complex number to a logical value will result in error. For example, NaN && 0 and (1+i) && 0 throw the following errors:

Error in Line 1(1). NaN is not convertible to a logical.
Error at Line 1(1). A complex number is not convertible to a logical.